<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>选择用户控件</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
        <meta name="generator" content="www.leipi.org" />
        <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
        <!--[if lte IE 6]>
        <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-ie6.css">
        <![endif]-->
        <!--[if lte IE 7]>
        <link rel="stylesheet" type="text/css" href="bootstrap/css/ie.css">
        <![endif]-->
        <link rel="stylesheet" href="leipi.style.css">
        <script type="text/javascript" src="../dialogs/internal.js"></script>
        <script type="text/javascript">
            function createElement(type, name)
            {
                var element = null;
                try {
                    element = document.createElement('<' + type + ' name="' + name + '">');
                } catch (e) {
                }
                if (element == null) {
                    element = document.createElement(type);
                    element.name = name;
                }
                return element;
            }
        </script>
    </head>
    <body>
        <div class="content">
            <table class="table table-bordered table-striped table-hover">
                <thead>
                    <tr>
                        <th><span>控件名称</span><span class="label label-important">*</span></th>
                    </tr>
                    <tr>
                        <td>
                            <input id="orgname" type="text" placeholder="必填项"/>
                        </td>
                    </tr>
                </thead>
                <tbody id='itemAttr'>
                    <tr>
                        <th><span>控件样式</span></th>
                    </tr>
                    <tr>
                        <td>
                            宽 <input id="orgwidth" type="text" value="150" class="input-small span1" placeholder="auto"/> px
                            &nbsp;&nbsp;
                            字体大小 <input id="orgfontsize" type="text" value="" class="input-small span1" placeholder="auto"/> px

                        </td>
                    </tr>
                </tbody>

            </table>
        </div>
        <script type="text/javascript" src="/Public/Admin/js/jquery.min.js"></script>
        <script type="text/javascript">
            var oNode = null, thePlugins = 'macros';
            window.onload = function () {
                if (UE.plugins[thePlugins].editdom) {
                    oNode = UE.plugins[thePlugins].editdom;
                    var gTitle = oNode.getAttribute('title').replace(/&quot;/g, "\""), gFontSize = oNode.getAttribute('orgfontsize'), gWidth = oNode.getAttribute('orgwidth');
                    gTitle = gTitle == null ? '' : gTitle;
                    $G('orgname').value = gTitle;
                    //if( oNode.tagName == 'INPUT' ) {}
                    $G('orgname').value = gTitle;
                    $G('orgwidth').value = gWidth;
                    $G('orgfontsize').value = gFontSize;
                }
            }

            dialog.oncancel = function () {
                if (UE.plugins[thePlugins].editdom) {
                    delete UE.plugins[thePlugins].editdom;
                }
            };
            dialog.onok = function () {
                if ($G('orgname').value == '') {
                    alert('控件名称不能为空');
                    return false;
                }
                var gTitle = $G('orgname').value.replace(/\"/g, "&quot;"), gFontSize = $G('orgfontsize').value, gWidth = $G('orgwidth').value;
                if (!oNode) {
                    try {
                        /*
                         if ( $G('orgtype').value.indexOf('sys_list')>0 ) {
                         oNode = document.createElement("select");
                         var objOption = new Option('{macros}', '');
                         oNode.options[oNode.options.length] = objOption;
                         } else {
                         //input
                         }*/
                        oNode = createElement('p', 'leipiNewField');
                        oNode.setAttribute('class', 'auto_user');
                        oNode.innerHTML = '<img class="checkUser opinter" src="/Public/Admin/images/user.png" />';

                        //                oNode.setAttribute('title',gTitle);
                        //                oNode.setAttribute('name','leipiNewField');
                        //                oNode.setAttribute('leipiPlugins',thePlugins);
                        //                oNode.setAttribute('orgtype',gType); 
                        //                if( $G('orghide').checked ) {
                        //                    oNode.setAttribute('orghide', '1' ) ;
                        //                } else {
                        //                    oNode.setAttribute('orghide', '0' ) ;
                        //                }
                        //                if( gFontSize != '' ) {
                        //                    oNode.style.fontSize = gFontSize + 'px';
                        //                    oNode.setAttribute('orgfontsize',gFontSize );
                        //                }
                        //                if( gWidth != '' ) {
                        //                    oNode.style.width = gWidth + 'px';
                        //                    oNode.setAttribute('orgwidth',gWidth );
                        //                }
                        editor.execCommand('insertHtml', oNode.outerHTML);
                        return true;
                    } catch (e) {
                        try {
                            editor.execCommand('error');
                        } catch (e) {
                            alert('控件异常，请到 [雷劈网] 反馈或寻求帮助！');
                        }
                        return false;
                    }
                } else {
                    var norgname = oNode.getAttribute('name').replace(/\"/g, "&quot;");
                    var oNewNode = null;
                    domUtils.remove(oNode, false);  //删除当前控件，再创建一个新的
                    /*
                     if ( $G('orgtype').value.indexOf('sys_list') > 0 ) {
                     oNewNode = document.createElement("select");
                     var objOption = new Option('{macros}', '');
                     oNewNode.options[oNewNode.options.length] = objOption;
                     }*/
                    oNewNode = createElement('input', 'leipiNewField');
                    oNewNode.setAttribute('type', 'text');
                    oNewNode.setAttribute('value', '{macros}');
                    oNewNode.setAttribute('title', gTitle);
                    oNewNode.setAttribute('name', norgname);
                    oNewNode.setAttribute('leipiPlugins', thePlugins);

                    if (gFontSize != '') {
                        oNewNode.style.fontSize = gFontSize + 'px';
                        oNewNode.setAttribute('orgfontsize', gFontSize);
                    } else {
                        oNewNode.setAttribute('orgfontsize', '');
                    }
                    if (gWidth != '') {
                        oNewNode.style.width = gWidth + 'px';
                        oNewNode.setAttribute('orgwidth', gWidth);
                    } else {
                        oNewNode.setAttribute('orgwidth', '');
                    }
                    editor.execCommand('insertHtml', oNewNode.outerHTML);
                    delete UE.plugins[thePlugins].editdom;
                }
            };

            function insertAfter(newElement, targetElement) { // newElement是要追加的元素 targetElement 是指定元素的位置 
                var parent = targetElement.parentNode; // 找到指定元素的父节点 
                if (parent.lastChild == targetElement) { // 判断指定元素的是否是节点中的最后一个位置 如果是的话就直接使用appendChild方法 
                    parent.appendChild(newElement, targetElement);
                } else {
                    parent.insertBefore(newElement, targetElement.nextSibling);
                }
                ;
            }

        </script>
    </body>
</html>
